--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit 7d1de23ea9d142b312be72b2ec944785c80a7933
Parents : 7759264
Author : Mark Qvist <mark@unsigned.io>
Date : 2024-12-11T13:57:40+01:00
Serve repository over HTTPS
Changes
2 files changed, 17 insertions(+), 3 deletions(-)
Diff
diff --git a/sbapp/main.py b/sbapp/main.py
index 22623b80..a8034c6e 100644
--- a/sbapp/main.py
+++ b/sbapp/main.py
@@ -3748,12 +3748,12 @@ class SidebandApp(MDApp):
ips = getIP()
if ips == None or len(ips) == 0:
- info += "The repository server is running, but the local device IP address could not be determined.\n\nYou can access the repository by pointing a browser to: http://DEVICE_IP:4444/"
+ info += "The repository server is running, but the local device IP address could not be determined.\n\nYou can access the repository by pointing a browser to: https://DEVICE_IP:4444/"
self.reposository_url = None
else:
ipstr = ""
for ip in ips:
- ipstr += "http://"+str(ip)+":4444/\n"
+ ipstr += "https://"+str(ip)+":4444/\n"
self.reposository_url = ipstr
ms = "" if len(ips) == 1 else "es"
diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py
index 2690fde8..9ad25ddd 100644
--- a/sbapp/sideband/core.py
+++ b/sbapp/sideband/core.py
@@ -239,6 +239,9 @@ class SidebandCore():
else:
sideband_dir = os.path.dirname(os.path.abspath(__file__))
self.webshare_dir = os.path.abspath(os.path.join(sideband_dir, "..", "share"))
+
+ self.webshare_ssl_key_path = self.app_dir+"/app_storage/ssl_key.pem"
+ self.webshare_ssl_cert_path = self.app_dir+"/app_storage/ssl_cert.pem"
self.first_run = True
self.saving_configuration = False
@@ -4674,6 +4677,7 @@ class SidebandCore():
from http import server
import socketserver
import json
+ import ssl
webshare_dir = self.webshare_dir
port = 4444
@@ -4721,7 +4725,17 @@ class SidebandCore():
self.wfile.write(es.encode("utf-8"))
socketserver.TCPServer.allow_reuse_address = True
- with socketserver.TCPServer(("", port), RequestHandler) as webserver:
+ class ThreadedHTTPServer(socketserver.ThreadingMixIn, server.HTTPServer):
+ daemon_threads = True
+
+ with ThreadedHTTPServer(("", port), RequestHandler) as webserver:
+ from sideband.certgen import ensure_certificate
+
+ ensure_certificate(self.webshare_ssl_key_path, self.webshare_ssl_cert_path)
+ ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
+ ssl_context.load_cert_chain(certfile=self.webshare_ssl_cert_path, keyfile=self.webshare_ssl_key_path)
+ webserver.socket = ssl_context.wrap_socket(webserver.socket, do_handshake_on_connect=False, server_side=True)
+
self.webshare_server = webserver
webserver.serve_forever()
self.webshare_server = None
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────